import sys
import pygetwindow as gw
import pyautogui
import win32gui
import ctypes

from PyQt5.QtWidgets import QApplication, QWidget,QPushButton
from PyQt5.QtCore import QPoint

user32 = ctypes.windll.user32
def main():
    app = QApplication(sys.argv)
    
    window = QWidget()
    window.setWindowTitle("My Window")
    button = QPushButton('Click me!', window)
    button.move(50, 50)
    
    window.show()
    sys.exit(app.exec_())
    
#调整指定窗口的大小 
#specific_window 需要调整的窗口
#width 需要调整的宽度
#height 需要调整的高度
def setWindowsSize(specific_window,width,height):
    specific_window.move(-specific_window.left, -specific_window.top)
    specific_window.resize(width-specific_window.width, height-specific_window.height)
    
# 移动位置
# startX 起始X轴位置
# startY 起始Y轴位置
# endX 结束X轴位置
# endY 结束Y轴位置
# duration 移动速度
def movePoint(startX,startY,endX,endY,duration):
    # 按下鼠标的位置
    pyautogui.moveTo(startX, startY)
    # 按下鼠标左键
    pyautogui.mouseDown()

    # 模拟拖拽操作，移动鼠标到结束位置
    pyautogui.moveTo(endX, endY, duration=duration)  # duration 参数控制移动速度

    # 释放鼠标左键
    pyautogui.mouseUp()
def getWindows(Title,width,height):
    specific_window = gw.getWindowsWithTitle(Title)[0]
    setWindowsSize(specific_window,width,height)

    # 将此窗口设为前台窗口
    specific_window.activate()
    # 等待窗口变为活动状态
    pyautogui.sleep(1)

    # 触发点击事件
    
    # 移动位置
    # movePoint(200,200,200,400,1)
    
    specific_window.show()
    print(specific_window.left)
    
#模拟点击某个位置    
def imitateClick(x,y):
    pyautogui.click(x=x, y=y)
    pyautogui.sleep(0.1)
    
#出城坐标
chuCheng=[426,593]
#首次出城坐标
OneChuCheng=[430,500]
#回城坐标
huiCheng=[666,1163]
#出城等待时间
chuChengWaitTime=4.5

# 贫瘠营地
def  pjyd():
    print(12)
    imitateClick(chuCheng[0],chuCheng[1])
    
    imitateClick(189,446)
    imitateClick(519,391)
    
    pyautogui.sleep(chuChengWaitTime)
    
    movePoint(300,760,729,609,2)
    pyautogui.sleep(2)
    
    imitateClick(huiCheng[0],huiCheng[1])
    pyautogui.sleep(4.5)

# 寒风营地
def  hfyd():
    imitateClick(chuCheng[0],chuCheng[1])
    imitateClick(200,530)
    imitateClick(491,659)
    
    pyautogui.sleep(chuChengWaitTime)
    movePoint(300,760,729,609,3)
    pyautogui.sleep(8.5)
    
    imitateClick(huiCheng[0],huiCheng[1])
    pyautogui.sleep(1.5)
# 污染哨站
def  wrsz():
    imitateClick(OneChuCheng[0],OneChuCheng[1])
    imitateClick(200,530)
    imitateClick(555,385)
    
    pyautogui.sleep(chuChengWaitTime)

    pyautogui.sleep(3)
    movePoint(361,762,356,863,5.8)

    pyautogui.sleep(2)
    imitateClick(huiCheng[0],huiCheng[1])
    pyautogui.sleep(4.5)
    
def getWindowsAll():
    # 获取所有窗口
    all_windows = gw.getAllTitles()
    # 打印所有窗口的标题
    for window_title in all_windows:
        print(window_title)    
# 重启小程序
def cq():
    pyautogui.click(x=560, y=30)
    pyautogui.click(x=446, y=351)
    pyautogui.sleep(7)
        
if __name__ == '__main__':
    getWindowsAll()
    while(True):
        cq()
        getWindows('百炼英雄',740,1367)
        #污染哨站
        wrsz()
        #贫瘠营地
        pjyd()
        #寒风营地
        hfyd()

    